Skip to content

feat: send mobile braze notifications LEARNER-10298 #36272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

jawad-khan
Copy link
Member

@jawad-khan jawad-khan commented Feb 19, 2025

Description

Send braze notification to mobile users. This change will pick braze campaign ids from db and send notification trigger to braze.
LEARNER-10298
Useful information to include:

  • This change will effect mobile users only.

Supporting information

Jira issue: https://2u-internal.atlassian.net/browse/LEARNER-10298

Deadline

ASAP.

@miankhalid
Copy link

@jawad-khan can you fix the failing checks here? before we request Infinity folks to give this PR a pass, thanks!

@jawad-khan jawad-khan force-pushed the jawad/LEARNER-10298 branch 4 times, most recently from 12f4356 to 5cdb65d Compare March 13, 2025 09:00
@@ -266,3 +267,25 @@ def get_core_config(self, app_name) -> Dict:
}
"""
return self.get_notification_types(app_name).get('core', {})


class NotificationBrazeCampaigns(TimeStampedModel):
Copy link
Contributor

@AhtishamShahid AhtishamShahid Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be a model it should be a django setting, Emails sent through braze also require campaing_id that is stored in Django settings. Please review how Braze is integrated into edx-platform for emails.
https://github.com/openedx/edx-ace/blob/64023b0b6a92fd990bcae2c79cce2ae2b2d3de6c/edx_ace/channel/braze.py#L56

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted mobile team to have the flexibility of adding braze campaign ids whenever they want. Plus it gives extra control on disabling push notifications for a certain notification type.

send_braze_notification_to_mobile_users(push_notification_audience, generated_notification)


def send_braze_notification_to_mobile_users(audience_ids, notification_object):
Copy link
Contributor

@AhtishamShahid AhtishamShahid Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending push notifications through braze should be part of edx-ace , a new channel can be created for this in edx-ace like this
https://github.com/openedx/edx-ace/blob/master/edx_ace/channel/push_notification.py

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some information on the initiative that this is part of? e.g., is this linked to a product proposal, or are there any public tickets or docs explaining the need for the new braze model?

@jawad-khan
Copy link
Member Author

Can you provide some information on the initiative that this is part of? e.g., is this linked to a product proposal, or are there any public tickets or docs explaining the need for the new braze model?

Unfortunately there is no public ticket or documentation for it yet. We are implementing push notification using braze for mobile devices. This PR is still in progress and we might remove this braze model.

@kdmccormick kdmccormick marked this pull request as draft April 9, 2025 14:49
@kdmccormick
Copy link
Member

Okay, I have converted it to Draft since it is still in progress. Just to set expectations, the edx-platform maintenance team is unlikely to accept new code that ties the core platform to Braze (especially data models) unless there is a compelling product use case for the community.

@jawad-khan jawad-khan force-pushed the jawad/LEARNER-10298 branch 2 times, most recently from 35e4b16 to bc28321 Compare April 24, 2025 18:43
@jawad-khan jawad-khan marked this pull request as ready for review April 24, 2025 18:43
@jawad-khan jawad-khan force-pushed the jawad/LEARNER-10298 branch from bc28321 to d060159 Compare April 24, 2025 18:47
@jawad-khan
Copy link
Member Author

@kdmccormick I have decoupled core platform from edx-braze-client and removed data model. Also changing the status of PR since its almost ready.

@kdmccormick
Copy link
Member

Hey @jawad-khan. By installing edx-braze-client as a base edx-platform requirement, this PR would still be adding Braze-specific logic and requirements to edx-platform, which we cannot accept.

That said, thank you for your work on this--I think it's much closer to what we need. What we need is for the vendor-specific logic to be implemented through a pluggable backend rather than through a base-requirement library. My understanding is that edx-ace is meant to be that pluggable backend, so I am little confused about this PR, and unsure what exactly to recommend.

Could you share the product proposal or design docs associated with this PR? That would help me recommend a path forward.

@jawad-khan
Copy link
Member Author

Hi @kdmccormick. I am thinking of this solution in edx-ace. By removing edx-braze-client from base.in in edx-ace we can achieve this. What do you think of this solution?

I'll try to collect any public documentation we have for you tomorrow.

sender_id = context.pop('sender_id', None)
default_web_config = get_default_values_of_preference(app_name, notification_type).get('web', False)
generated_notification_audience = []
push_notification_audience = []
is_push_notification_enabled = ENABLE_PUSH_NOTIFICATIONS.is_enabled()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use CourseWaffleFlag here. This will give more control when testing on stage and on prod

Comment on lines 301 to 302
(settings.NOTIFICATION_CREATION_BATCH_SIZE, 10, 7),
(settings.NOTIFICATION_CREATION_BATCH_SIZE + 10, 12, 10),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think query count should be +2 not +3. One query for fetching waffle flag and second to get list of emails.
  • Purpose of this test case is to make sure that NOTIFICATION_CREATION_BATCH_SIZE is optimized. It is better to keep changes in this test case to minimum. i.e. we can set push waffle flag to False and see that if it only increases 1 query count. If change is more than +1, we need to update batch size accordingly

app_label="notifications", name="braze_push"
).personalize(recipient, 'en', context)
message.options['emails'] = emails
message.options['braze_campaign'] = notification_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to add

message.options['skip_disable_user_policy'] = True

See PR

@@ -254,6 +258,7 @@ def test_send_with_app_disabled_notifications(self, app_name, notification_type)
self.assertIsNone(notification)

@override_waffle_flag(ENABLE_NOTIFICATIONS, active=True)
@override_waffle_flag(ENABLE_PUSH_NOTIFICATIONS, active=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For test cases, which don't require push notifications to be enabled, I think we should skip override_waffle_flag for them

@jawad-khan jawad-khan changed the title feat: send mobile braze notifications feat: send mobile braze notifications LEARNER-10298 Apr 30, 2025
@jawad-khan jawad-khan force-pushed the jawad/LEARNER-10298 branch from a8147ee to 078e4b5 Compare May 5, 2025 11:37
Comment on lines 57 to 61
# .. toggle_use_cases: temporary, open_edx
# .. toggle_creation_date: 2025-02-11
# .. toggle_target_removal_date: 2026-02-11
# .. toggle_warning: When the flag is ON, Notifications will go through using braze on mobile devices.
# .. toggle_tickets: LEARNER-10298
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggle_tickets must be a public link.

If this truly is a temporary toggle with target removal of 2026, then the linked ticket should give us maintainers a way to check on the status of this removal plan.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this toggle ticket here, I just followed template from other waffle flags. Also I don't think we need it temporarily. I'll update toggle info.

Comment on lines +21 to +22
if notification_object.app_name != 'discussion':
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain this with a comment.

Comment on lines 35 to 36
sender = User.objects.get(id=sender_id)
recipient = Recipient(sender.id, sender.email)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably just confused here, but could you explain why sender and recipient refer to the same user?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a Recipient object to call PushNotificationMessageType.personalize method, otherwise we don't need this recipient. I have added send here in case we might need sender in future in the context.
I'll add a comment to clear this confusion.

Comment on lines 14 to 16
def send_ace_msg_to_braze_push_channel(audience_ids, notification_object, sender_id):
"""
Send mobile notifications using ace braze_push channel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[This is my primary review comment]

I am thinking of openedx/edx-enterprise#2352 in edx-ace. By removing edx-braze-client from base.in in edx-ace we can achieve this. What do you think of this solution?

Thank you for linking that. I don't think that would solve the underlying issue, which is: you are building push notifications support specifically for Braze users. It is not clear to me why you are doing that instead of building general push notification support, with Braze as a configurable backend.

However, maybe there is a piece of context I am missing? I would be happy to discuss the appropriateness of a generic approach vs. a Braze specific approach, but I cannot do that, because there is no public supporting information for this PR-- the product goal, the timeline, the details of the overall initative-- these are all unavailable to me or any other community member. Without support information, this will not merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdmccormick We are working on product proposal which we can make public for open source community.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect Moiz, thank you.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdmccormick is there anything else required for this PR to be moved to merged?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdmccormick I have made this approach generic and its not linked with braze anymore. Let me know if anything else is needed.

@kdmccormick kdmccormick marked this pull request as draft May 5, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants